package com.yhert.project.game.server01.mine.websocket;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;

@Controller
@MessageMapping("/mine")
public class MinWebSocket {
	@Autowired
	private SimpMessagingTemplate messagingTemplate;

	@MessageMapping("/out")
	@SendTo("/topic/mine/msg")
	public String send(String msg) throws Exception {
		String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
		String result = "[" + format + "]:" + msg;
		messagingTemplate.convertAndSend("/topic/mine/news", result + ":news");
		return result;
	}
}
